package top.kaoshanji.p1ch01d;

import java.io.*;

/**
 * 代码清单 p1ch01d-03：使用try-with-resource语句管理两个资源的示例(1.5节)
 * author kaoshanji
 * ^_^
 * create time 2024/12/22 20:28
 */
public class MultipleResourcesUsage {

    public void copyFile(String fromPath, String toPath) throws IOException {

        try (InputStream input = new FileInputStream(fromPath);
             OutputStream output = new FileOutputStream(toPath)) {

            byte[] buffer = new byte[8192];
            int len = -1;
            while ((len = input.read(buffer)) != -1) {
                output.write(buffer, 0, len);
            }
        }

    }



}
